package com.ayz.gateway.client.executor.defaults;


import com.ayz.gateway.client.executor.RequestExecutor;
import com.ayz.gateway.client.executor.RequestExecutorRegistry;
import lombok.Data;

import java.util.HashMap;

/**
 * @ClassName DefaultRequestExecutorRegistry
 * @Description TODO: 默认的请求执行器注册器
 * @Author 快乐的星球
 * @Date 2023/5/20 11:46
 * @Version 1.0
 **/
@Data
public class DefaultRequestExecutorRegistry implements RequestExecutorRegistry {
    /**
     * 存储 请求编码与对应的请求执行器的注册表
     */
    private final HashMap<Integer, RequestExecutor> requestExecutorMap=new HashMap<>();
    @Override
    public void registry(int requestCode, RequestExecutor requestExecutor) {
        assert  requestExecutor!=null;
        this.requestExecutorMap.put(requestCode,requestExecutor);
    }
    @Override
    public RequestExecutor getRequestExecutor(int requestCode) {
        return this.requestExecutorMap.get(requestCode);
    }
    @Override
    public void unRegistry(int requestCode) {
        this.requestExecutorMap.remove(requestCode);
    }
}
